home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / upc12bs1.zip / UUCICO / uuport.c < prev    next >
C/C++ Source or Header  |  1993-09-30  |  5KB  |  183 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u p o r t . c                                                 */
  3. /*                                                                    */
  4. /*    suspend/resume uupoll/uucico daemon (for OS/2)                  */
  5. /*                                                                    */
  6. /*    Author: Kai Uwe Rommel                                          */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------*/
  10. /*       Copyright (c) 1993 by Kai Uwe Rommel                         */
  11. /*--------------------------------------------------------------------*/
  12.  
  13. /*--------------------------------------------------------------------*/
  14. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  15. /*       Wonderworks.                                                 */
  16. /*                                                                    */
  17. /*       All rights reserved except those explicitly granted by       */
  18. /*       the UUPC/extended license agreement.                         */
  19. /*--------------------------------------------------------------------*/
  20.  
  21. /*--------------------------------------------------------------------*/
  22. /*                          RCS Information                           */
  23. /*--------------------------------------------------------------------*/
  24.  
  25. /*
  26.  *    $Id: uuport.c 1.3 1993/10/01 02:36:45 dmwatt Exp $
  27.  *
  28.  *    Revision history:
  29.  *    $Log: uuport.c $
  30.  * Revision 1.3  1993/10/01  02:36:45  dmwatt
  31.  * Correct increment of pointer to pipe name
  32.  *
  33.  * Revision 1.2  1993/09/29  04:49:20  ahd
  34.  * Use standard port name
  35.  *
  36.  */
  37.  
  38. /* see uucico\suspend2.c for description */
  39.  
  40. /* exit codes:
  41.  *   0 = success
  42.  *   1 = incorrect usage of uuport
  43.  *   2 = no uucico running on that port
  44.  *   3 = communication error between uuport and the uucico
  45.  *   4 = error, uucico cannot currently be suspended
  46.  */
  47.  
  48. /*--------------------------------------------------------------------*/
  49. /*                        System include files                        */
  50. /*--------------------------------------------------------------------*/
  51.  
  52. #include <stdlib.h>
  53. #include <stdio.h>
  54. #include <io.h>
  55. #include <fcntl.h>
  56. #include <string.h>
  57. #include <ctype.h>
  58.  
  59. /*--------------------------------------------------------------------*/
  60. /*                    UUPC/extended include files                     */
  61. /*--------------------------------------------------------------------*/
  62.  
  63. #include "lib.h"
  64. #include "timestmp.h"
  65. #define  NO_SUSPEND_FUNCTIONS
  66. #include "suspend.h"
  67.  
  68. /*--------------------------------------------------------------------*/
  69. /*       u s a g e                                                    */
  70. /*                                                                    */
  71. /*       Report program usage                                         */
  72. /*--------------------------------------------------------------------*/
  73.  
  74. static void usage(const char *program)
  75. {
  76.   printf("Usage:\t%s\t[-sr] [\\\\server\\]portname\n", program);
  77.   exit(1);
  78.  
  79. } /* usage */
  80.  
  81. /*--------------------------------------------------------------------*/
  82. /*       m a i n                                                      */
  83. /*                                                                    */
  84. /*       Main program, of course                                      */
  85. /*--------------------------------------------------------------------*/
  86.  
  87. int main(int argc, char **argv)
  88. {
  89.   int file;
  90.   char name[64], pipe[FILENAME_MAX];
  91.   char *ptr, cmd = 'Q';
  92.  
  93.   banner( argv );
  94.  
  95.   if ( argc != 2 && argc != 3 )
  96.     usage(argv[0]);
  97.  
  98.   if ( argv[1][0] != '-' )
  99.     strcpy(name, argv[1]);
  100.   else
  101.   {
  102.     if ( argv[1][2] != 0 )
  103.       usage(argv[0]);
  104.  
  105.     switch ( tolower(argv[1][1]) )
  106.     {
  107.        case 's':
  108.          cmd = 'S';
  109.          break;
  110.        case 'r':
  111.          cmd = 'R';
  112.          break;
  113.        default:
  114.          usage(argv[0]);
  115.     }
  116.  
  117.     strcpy(name, argv[2]);
  118.   }
  119.  
  120.   if ( strncmp(name, "\\\\", 2) == 0 )  /* server specified ? */
  121.   {
  122.     ptr = name + 2;
  123.  
  124.     if ( (ptr = strchr(ptr, '\\')) == NULL )
  125.     {
  126.       printf("invalid port '%s' specified.\n", name);
  127.       return 1;
  128.     }
  129.  
  130.     *ptr++ = '\0';
  131.     strcpy(pipe, name);
  132.     strcat(pipe, SUSPEND_PIPE );
  133.     strcat(pipe, ptr);
  134.   }
  135.   else
  136.   {
  137.     strcpy(pipe, SUSPEND_PIPE );
  138.     strcat(pipe, name);
  139.   }
  140.  
  141.   if ( (file = open(pipe, O_RDWR, 0)) == -1 )
  142.   {
  143.     printf("No port '%s' currently used by any uucico.\n", name);
  144.     return 2;
  145.   }
  146.  
  147.   if ( cmd != 'Q' )
  148.     printf("Waiting for uucico on port '%s' to %s ... ",
  149.            name, cmd == 'S' ? "suspend" : "resume");
  150.  
  151.   if ( write(file, &cmd, 1) != 1 )
  152.   {
  153.     printf("\nError sending message to uucico.\n");
  154.     return 3;
  155.   }
  156.   if ( read(file, &cmd, 1) != 1 )
  157.   {
  158.     printf("\nError reading message from uucico.\n");
  159.     return 3;
  160.   }
  161.  
  162.   close(file);
  163.  
  164.   switch ( cmd )
  165.   {
  166.      case 'O':
  167.        printf("OK\n");
  168.        break;
  169.      case 'S':
  170.        printf("uucico on port '%s' is suspended.\n", name);
  171.        break;
  172.      case 'R':
  173.        printf("uucico on port '%s' is active.\n", name);
  174.        break;
  175.      default:
  176.        printf("FAILED\n");
  177.        return 4;
  178.   }
  179.  
  180.   return 0;
  181.  
  182. } /* main */
  183.